package com.yoga.service.impl;

import com.yoga.entity.*;
import com.yoga.mapper.YogaMymoneyDao;
import com.yoga.mapper.YogaPrivaterequestDao;
import com.yoga.mapper.YogaUserDao;
import com.yoga.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private YogaUserDao userDao;
    @Autowired
    private YogaMymoneyDao mymoneyDao;
    @Autowired
    private YogaPrivaterequestDao privaterequestDao;

    @Override
    public List<YogaUser> getAllUser() {
        return userDao.selectByExample(null);
    }

    @Override
    public YogaUser getUserById(Integer uid) {
        return userDao.selectByPrimaryKey(uid);
    }

    @Override
    public boolean addUser(YogaUser coach) {
        return userDao.insertSelective(coach)>0?true:false;
    }

    @Override
    public boolean updateUser(YogaUser coach) {
        return userDao.updateByPrimaryKeySelective(coach)>0?true:false;
    }

    @Override
    public boolean deleteUser(Integer uid) {
        return userDao.deleteByPrimaryKey(uid)>0?true:false;
    }
    @Override
    public YogaMymoney checkMyMoney(Integer uid) {
        YogaMymoneyExample example = new YogaMymoneyExample();
        example.createCriteria().andUidEqualTo(uid);
        List<YogaMymoney> list = mymoneyDao.selectByExample(example);
        return list.size()>0? list.get(0):null;
    }

    @Override
    public List<YogaPrivaterequest> findMyClass(Integer uid) {
        YogaPrivaterequestExample example = new YogaPrivaterequestExample();
        example.createCriteria().andUidEqualTo(String.valueOf(uid));
        List<YogaPrivaterequest> list = privaterequestDao.selectByExample(example);
        return list;
    }
}
